package com.jnu.myllm.mapper;

import com.jnu.myllm.entity.User;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    // 别名与user类的成员变量名一致
    String baseSql = "select user_id as id, user_nickname as nickName, user_loginname as loginName" +
            ", user_loginpwd as loginPwd, user_score as score, user_img as img from users ";
    // 插入用户
    @Insert("insert into users values(default,#{u.nickName},#{u.loginName},#{u.loginPwd},#{u.score},#{u.img})")
    int insert(@Param("u") User user);

    // 通过用户账号查询用户
    @Select(baseSql + "where user_loginname=#{name}")
    User selectByLoginName(@Param("name") String loginName);

    // 通过用户id查询用户
    @Select(baseSql + "where user_id=#{uid}")
    User selectByUid(@Param("uid") int userId);

    // 更新指定账号用户的信息
    @Update("update users set user_nickname=#{u.nickName}, user_loginpwd=#{u.loginPwd}" +
            ", user_score=#{u.score} where user_id=#{u.id}")
    int update(@Param("u") User u);

}
